//
//  OrderEvaluationViewController.m
//  PigMarket
//
//  Created by 张敬 on 2019/9/12.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "OrderEvaluationViewController.h"
#import "OrderEvaluationTableViewCell.h"
#import "OrderCommentViewController.h"

@interface OrderEvaluationViewController ()

@end

@implementation OrderEvaluationViewController

#pragma mark - lifecycle methods

- (void)setupUI{

    {
        self.baseNavView.navTitleLabel.text = @"晒单评价";
    }
    
}

- (void)setupLayout{
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(TJ_NavBarHeight + 10, 0, 0, 0));
    }];
}

#pragma mark - networking methods

- (void)initData{
    
    @weakify(self);
    [[[MeatOrderApi sharedInstance] getOrderEvaluationByGoodId:@1 shopId:@"1"] subscribeNext:^(MeatOrderEvaluationSuccessModel * _Nullable x) {
        
    } error:^(NSError * _Nullable error) {
        
    }];

    
}

#pragma mark - tableview.delegate methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return section == 0 ?2 :1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return section == 1 ? 44 :0.01;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *sectionView = [[UIView alloc] init];
    sectionView.backgroundColor = mBackgroudColor;
    
    UILabel *label = [UILabel makeLabelWithText:@"已评价商品" textColor:UIColorFromRGB(0x969696) font:mFont(14) textAliment:0];
    label.frame = CGRectMake(15, 10, 100, 34);
    [sectionView addSubview:label];
    
    return section == 1 ?sectionView :nil;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    OrderEvaluationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderEvaluationTableViewCell"];
    cell.type = indexPath.section == 0 ?OrderEvaluationType_Default :OrderEvaluationType_Already;
    
    @weakify(self);
    cell.dealEvlationBlock = ^{
        @strongify(self);
        OrderCommentViewController *vc = [[OrderCommentViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    };
    
    return cell;
}


#pragma mark - tableview.delegate methods

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

#pragma mark - setter methods
#pragma mark - getter methods

- (void)registerTableViewCell
{
   // self.tableView.hidden = YES;
    self.tableView.rowHeight = 86;
    
    self.tableView.separatorColor = mIconLineColor;
    [self.tableView registerClass:[OrderEvaluationTableViewCell class] forCellReuseIdentifier:@"OrderEvaluationTableViewCell"];
}


@end
